def is_prime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

def closest_prime_number(num):
    num = int(num)
    if is_prime(num):
        return num
    lower = num - 1
    upper = num + 1
    while not is_prime(lower) and not is_prime(upper):
        lower -= 1
        upper += 1
    if is_prime(lower):
        return lower
    else:
        return upper

input_words = input().split()
number = "".join([str(input_words.index(word)) for word in input_words if word in ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]])

if len(number) != 3:
    print("wrong input")
else:
    result = closest_prime_number(number)
    print(result)
